package com.itheima.day13work;

public class Food implements Runnable{
   private Desk desk;

    public Food(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {

        while (true) {
            synchronized (desk.getObj()) {
                if (desk.isFlag()) { //true 表示就餐者就食
                    System.out.println("顾客吃泡芙");
                    desk.setFlag(false);
                    int i = desk.getCount();
                    desk.setCount(--i);
                    desk.getObj().notifyAll();
                } else {
                    try {
                        if (desk.getCount()==0){
                            break; //如果达到就餐上限，结束循环
                        }
                        desk.getObj().wait();
                    } catch (InterruptedException e) {
                    }

                }

        }
        }

    }
}
